#include "Utils.h"
#include <string.h>
#include <stdio.h>
#include <unistd.h>
#include <wx/file.h>

//static const char* AutoMountCmds[4] = { "mkdir /tmp/rootfs ; mount /dev/mmcblk0p2 /tmp/rootfs; ", "mkdir /tmp/opt ; mount /dev/mmcblk0p3 /tmp/opt;", "mkdir ${rootfs} ; mount /dev/mmcblk0p2 ${rootfs}; ", "mkdir ${opt} ; mount /dev/mmcblk0p3 ${opt};"};
static const char* CmdTags[] = {"${recovery}", "${rootfs}", "${opt}", "${opt2}"};
static const char* MountPoints[] = {"", "/tmp/rootfs", "/tmp/opt", "/tmp/opt2"};


Utils::Utils()
{
    //ctor
}

Utils::~Utils()
{
    //dtor
}

Utils& Utils::Get()
{
    static Utils instance;
    return instance;
}

uint32_t Utils::GetNextRawfileIndex(const wxString& dir, uint32_t start)
{
    wxString path;

    for(uint32_t idx = start; ; ++ idx)
    {
        if(idx > 0)
        {
            path = wxString::Format(wxT("%s/%u"), dir, idx);
            if(!wxFile::Exists(path))
            {
                return idx;
            }
        }
    }
    return 0;
}

bool Utils::ProcessCmmandTags(wxString& cmd)
{
    for(int idx = 1; idx < sizeof(CmdTags)/sizeof(const char*); ++idx)
    {
        cmd.Replace(CmdTags[idx], MountPoints[idx]);
    }
    return true;
}

const char** Utils::GetMountPoints() const
{
    return (const char**)MountPoints;
}
